home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / standards / sgml / nist / parse1 / dtdms.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-13  |  9.7 KB  |  280 lines

  1. /* National Institute of Standards and Technology (NIST)
  2. /* National Computer System Laboratory (NCSL)
  3. /* Office Systems Engineering (OSE) Group
  4. /* ********************************************************************
  5. /*                            D I S C L A I M E R
  6. /*                              (March 8, 1989)
  7. /*  
  8. /* There is no warranty for the NIST NCSL OSE SGML parser and/or the NIST
  9. /* NCSL OSE SGML parser validation suite.  If the SGML parser and/or
  10. /* validation suite is modified by someone else and passed on, NIST wants
  11. /* the parser's recipients to know that what they have is not what NIST
  12. /* distributed, so that any problems introduced by others will not
  13. /* reflect on our reputation.
  14. /* 
  15. /* Policies
  16. /* 
  17. /* 1. Anyone may copy and distribute verbatim copies of the SGML source
  18. /* code as received in any medium.
  19. /* 
  20. /* 2. Anyone may modify your copy or copies of SGML parser source code or
  21. /* any portion of it, and copy and distribute such modifications provided
  22. /* that all modifications are clearly associated with the entity that
  23. /* performs the modifications.
  24. /* 
  25. /* NO WARRANTY
  26. /* ===========
  27. /* 
  28. /* NIST PROVIDES ABSOLUTELY NO WARRANTY.  THE SGML PARSER AND VALIDATION
  29. /* SUITE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
  30. /* EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  31. /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  32. /* THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS
  33. /* WITH YOU.  SHOULD THE SGML PARSER OR VALIDATION SUITE PROVE DEFECTIVE,
  34. /* YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  35. /* 
  36. /* IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL NIST BE LIABLE FOR
  37. /* DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL,
  38. /* INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  39. /* INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
  40. /* BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A
  41. /* FAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY
  42. /* NIST) THE PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF
  43. /* SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  44. */
  45.  
  46. /************************************************************************/
  47. /*   TITLE:          SGML PARSER                                        */
  48. /*   SYSTEM:         DTD PROCESSOR                                      */
  49. /*   SUBSYSTEM:                                                         */
  50. /*   SOURCE FILE:    DTDMS.C                                            */
  51. /*   AUTHOR:         STEVE LINDEMAN                                     */
  52. /*                                                                      */
  53. /*   DATE CREATED:                                                      */
  54. /*   LAST MODIFIED:                                                     */
  55. /*                                                                      */
  56. /*                  REVISIONS                                           */
  57. /*   WHEN      WHO            WHY                                       */
  58. /************************************************************************/
  59. #include <stdio.h>
  60. #include <setjmp.h>
  61. #include <unistd.h>
  62.  
  63. #include "qntyset.h"
  64. #include "dtd.h"
  65. #include "dtdfncs.h"
  66. #include "dtdglbl.h"
  67. #include "dtddefs.h"
  68. /* ============================================================ */
  69. /* == checks to see if there is an SGML declaration.  If     == */
  70. /* == there is, it will strip it out.                        == */
  71. /* ============================================================ */
  72. void dogetsgml()
  73. {
  74. #ifdef JJJ
  75.    char jarr[6];
  76.    char *comp="<!SGML";
  77.    int i,j,c;
  78.    int fnd=TRUE; /* assume true */
  79.  
  80.    for (i=0; i<6; i++) {
  81.       if ((jarr[i]=jgetc()) == EOF) {
  82.          fnd = FALSE;
  83.          break;
  84.       }
  85.       if (mycompare(jarr[i],comp[i]) == FALSE) {
  86.          fnd = FALSE;   /* lower case letters are also checked */
  87.          break;
  88.       }
  89.    }
  90.    if (fnd == FALSE) {
  91.       for (j=i; j>=0; j--) {
  92.          jungetc(jarr[j]);
  93.       }
  94.    }
  95.    else
  96.       while((c=jgetc()) != EOF && c != MDC);  /* read characters */
  97.    if (c == EOF)
  98.       terminate(1,"EOF found while in SGML declaration");
  99.    return;
  100. #endif
  101. }
  102. /* ============================================================ */
  103. /* == compares two characters for case INsensitive equality  == */
  104. /* ============================================================ */
  105. int mycompare(c1,c2)
  106. int c1,c2;
  107. {
  108.    if (c1 == c2)    /* if they are the same case and equal */
  109.       return(TRUE);
  110.    if (c1 > 'a' && c1 < 'z' )   /* if c1 is lower case */
  111.       if ((c1-32) == c2)
  112.          return(TRUE);
  113.    if (c2 > 'a' && c2 < 'z' )   /* if c2 is lower case */
  114.       if ((c2-32) == c1)
  115.          return(TRUE);
  116.    return(FALSE);
  117. }
  118.  
  119.  
  120. /*------------------------------------------------------*/
  121. /*         G E T _ M A R K E D _ S E C T I O N          */
  122. /*     This routine processes a marked section.  If     */
  123. /*     the section is an INCLUDE section, processing  */
  124. /*     is returned to gettoken, else the entire section  */
  125. /*     is processed and then control is returned.  */
  126. /*------------------------------------------------------*/
  127. void get_marked_section()
  128. {
  129.    register int inchar,statkey;
  130.    int begnum_open;
  131.    short moredata,close_read=FALSE;
  132.    if (++num_open_ms > TAGLVL)
  133.       syntxerr("Error: Number of open marked sections > TAGLVL");
  134.  
  135.    statkey = get_status_keyword();
  136.    INPPS();
  137.    if ((inchar=jgetc()) != '[')
  138.       syntxerr("Error: DSO not found in marked section.");
  139.  
  140.    switch(statkey) {
  141.    case MS_INCLUDE:
  142.       break;
  143.    case MS_RCDATA:
  144.       syntxerr("RCDATA marked section not legal");
  145.    case MS_CDATA:
  146.       syntxerr("CDATA marked section not legal");
  147.    case MS_IGNORE:
  148.       begnum_open = num_open_ms-1;   /* already incremented */
  149.       moredata = TRUE;
  150.       while(moredata && (inchar=jgetc())!=EOF)
  151.          if (inchar=='<' && (inchar=jgetc())=='!' && (inchar=jgetc())=='[') {
  152.             if (++num_open_ms > TAGLVL)
  153.                syntxerr("Error: Number open marked sections > TAGLVL.");
  154.          }
  155.          else
  156.             if (inchar==']' && (inchar=jgetc())==']' && (inchar=jgetc())==MARKUP_END) {
  157.                if (--num_open_ms == begnum_open)
  158.                   moredata = FALSE;
  159.             }
  160.             else
  161.                if ((char)inchar == EE)
  162.                   syntxerr("Error: Entity End found in IGNORE marked section.");
  163.       close_read = TRUE;
  164.       break;
  165.    default:
  166.       syntxerr("Software vault");
  167.       break;
  168.    }
  169.    if (!close_read && statkey!=MS_INCLUDE && statkey!=MS_CDATA && statkey!=MS_RCDATA) {
  170.       if ((inchar=jgetc())!=']' || (inchar=jgetc())!=']')
  171.          syntxerr("Error: MDO not found in marked section.");
  172.       if ((inchar=jgetc()) != MARKUP_END)
  173.          syntxerr("Error: MDC not found in marked section.");
  174.    }
  175.    return;
  176. }
  177.  
  178. /* ============================================ */
  179. /* == G E T S T A T U S K E Y W O R D        == */
  180. /* ==   Get the Status Keyword.            == */
  181. /* ============================================ */
  182. int get_status_keyword()
  183. {
  184.    int retval ,j;
  185.    char keyname[NAMELEN];
  186.  
  187.    retval = MS_INCLUDE; /* default status keyword */
  188.  
  189.    INPPS(); /* input the ps */
  190.  
  191.    while ((j=jgetc()) != '[' ) {
  192.       jungetc(j);
  193.       get_name(keyname);
  194.       if (strncmp(keyname,"IGNORE  ",NAMELEN) == 0)
  195.          retval = (MS_IGNORE > retval ? MS_IGNORE : retval);
  196.       else
  197.          if (strncmp(keyname,"CDATA   ",NAMELEN) == 0)
  198.             retval = (MS_CDATA > retval ? MS_CDATA : retval);
  199.          else
  200.             if (strncmp(keyname,"RCDATA  ",NAMELEN) == 0)
  201.                retval = (MS_RCDATA > retval ? MS_RCDATA : retval);
  202.             else
  203.                if (strncmp(keyname,"INCLUDE ",NAMELEN) == 0)
  204.                   retval = (MS_INCLUDE > retval ? MS_INCLUDE : retval);
  205.                else
  206.                   if (strncmp(keyname,"TEMP    ",NAMELEN) != 0)
  207.                      syntxerr("Error Illegal status keyword in marked section");
  208.       INPPS();
  209.    }
  210.    jungetc(j);
  211.    return(retval);
  212. }
  213. /* ============================================ */
  214. /* == G E T _ N A M E                   == */
  215. /* ==       Get the name.               == */
  216. /* ============================================ */
  217. void get_name(name)
  218. char *name;
  219. {
  220.    int j, i;
  221.    char *blank = name;
  222.  
  223.    for (i=0;i<NAMELEN+1;i++)  /* blank out the name string */
  224.       *blank++ = ' ';
  225.  
  226.    if (!isnmstrt(j=jgetc()))
  227.       syntxerr("Invalid status keyword name in marked section");
  228.    *name++ = TOUPPER(j);   /* make it uppercase */
  229.    ADDCHAR(j);
  230.    i = 0;
  231.    while (i < NAMELEN && isnmchar(j=jgetc())) {
  232.       *name++ = TOUPPER(j);
  233.       i++;
  234.       ADDCHAR(j);
  235.    }
  236.    if (i >= NAMELEN)
  237.       syntxerr("Status Keyword Name exceeds NAMELEN");
  238.    jungetc(j); /* unget the last character read */
  239. }
  240.  
  241.  
  242. /*------------------------------------------------------*/
  243. /*    G E T _ M S _ C L O S E S     */
  244. /*   This routine reads from 'indoc' as many */
  245. /*      marked section closes as possible.      */
  246. /*------------------------------------------------------*/
  247. void get_ms_closes()
  248. {
  249.    int inchar;
  250.    short more_ms_closes=TRUE;
  251.  
  252.    while(more_ms_closes && (inchar=jgetc())!=EOF) {
  253.       if (inchar == ']')
  254.          if ((inchar=jgetc()) == ']')
  255.             if ((inchar=jgetc()) == MARKUP_END) {
  256.                if (--num_open_ms == 0)
  257.                   more_ms_closes = FALSE;
  258.                if ((char)(inchar=jgetc()) != EE)
  259.                   jungetc(inchar);
  260.             }
  261.             else {
  262.                jungetc(inchar);
  263.                jungetc(']');
  264.                jungetc(']');
  265.                more_ms_closes = FALSE;
  266.             }
  267.          else {
  268.             jungetc(inchar);
  269.             jungetc(']');
  270.             more_ms_closes = FALSE;
  271.          }
  272.       else {
  273.          jungetc(inchar);
  274.          more_ms_closes = FALSE;
  275.       }
  276.    }
  277.    return;
  278. }
  279. /* ============================================================ */
  280.